package com.ruoyi.framework.web.service;

import java.util.ArrayList;
import java.util.List;


import com.ruoyi.project.baozhi.dept.domain.OrgDept;
import com.ruoyi.project.baozhi.dept.service.IOrgDeptService;
import com.ruoyi.project.insurance.contract.domain.Contract;
import com.ruoyi.project.insurance.contract.service.IContractService;
import com.ruoyi.project.insurance.insurance.domain.insurance;
import com.ruoyi.project.insurance.insurance.service.IinsuranceService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.dict.domain.DictData;
import com.ruoyi.project.system.dict.service.IDictDataService;
import com.ruoyi.project.system.dict.service.IDictTypeService;

/**
 * RuoYi首创 html调用 thymeleaf 实现字典读取
 * 
 * @author ruoyi
 */
@Service("dict")
public class DictService
{
    @Autowired
    private IDictTypeService dictTypeService;

    @Autowired
    private IinsuranceService insuranceService;

    @Autowired
    private IDictDataService dictDataService;

    @Autowired
    private IUserService userService;

    /**
     * 根据字典类型查询字典数据信息
     * 
     * @param dictType 字典类型
     * @return 参数键值
     */
    public List<DictData> getType(String dictType)
    {
        return dictTypeService.selectDictDataByType(dictType);
    }

    /**
     * 查询人员名称
     * @return
     */
    public List<DictData> getUser()
    {
        List<DictData> list1=new ArrayList<>();
        User user=new User();
        List<User> list = userService.selectUserList(user);
        long i=0;
        for (User user1 : list) {
            DictData dictData=new DictData();
            dictData.setDictLabel(user1.getUserName());
            dictData.setDictValue(user1.getStaffCode());
            dictData.setDictSort(i);
            i++;
            list1.add(dictData);
        }

        return list1;
    }

    /**
     * 查询险种名称
     * @return
     */
    public List<DictData> getinsuranceName()
    {
        List<DictData> list1=new ArrayList<>();
        User user=new User();
        insurance insurance=new insurance();
        List<insurance> list = insuranceService.selectinsuranceList(insurance);
        long i=0;
        for (insurance insurance1 : list) {
            DictData dictData=new DictData();
            dictData.setDictLabel(insurance1.getName());
            dictData.setDictValue(insurance1.getCode());
            dictData.setDictSort(i);
            i++;
            list1.add(dictData);
        }

        return list1;
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     * 
     * @param dictType 字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */
    public String getLabel(String dictType, String dictValue)
    {
        return dictDataService.selectDictLabel(dictType, dictValue);
    }

    /**
     * 根据字典类型和字典键值更新字典数据信息
     * @param dictType 字典类型
     * @param dictValue 字典键值
     * @param Value 更新的值
     * @return
     */
    public int setLabel(String dictType, String dictValue, String Value)
    {
        return dictDataService.updateDictLabel(dictType, dictValue,Value);
    }
}
